package kolekcje.eng.powtorka;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class SzafaGrajaca {

	private class TitleCompare implements Comparator<Song> {

		@Override
		public int compare(Song o1, Song o2) {
			return o1.getTitle().compareTo(o2.getTitle());
		}

	}

	private class ArtistCompare implements Comparator<Song> {

		@Override
		public int compare(Song o1, Song o2) {
			return o1.getArtist().compareTo(o2.getArtist());
		}

	}

	File plik = SzafaGrajacaSetter.plik;
	ArrayList<Song> songList;

	public SzafaGrajaca() {
		songList = new ArrayList<Song>();
		try {
			BufferedReader br = new BufferedReader(new FileReader(plik));
			String song;
			while ((song = br.readLine()) != null)
				addSong(song);
			br.close();
		} catch (FileNotFoundException e) {
			System.out.println("Nie odnalezionoe pliku");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void addSong(String song) {
		String[] elements = song.split("/");
		songList.add(new Song(elements[0], elements[1], elements[2],
				elements[2]));
	}

	public void pokazUtwory() {
		Collections.sort(songList);
		for (Song e : songList)
			System.out.println(e.toString());
		System.out.println();
		Collections.sort(songList, new ArtistCompare());
		for (Song e : songList)
			System.out.println(e.toString());
		System.out.println();
		Collections.sort(songList, new TitleCompare());
		for (Song e : songList)
			System.out.println(e.toString());
	}

}
